import os, re

pro = 93
epi = 150
n = 24

os.chdir(r'D:\0\ffmpeg\bin')


def dur(fn):
    f = os.popen4('ffprobe ' + fn)
    s = f[1].read()
    print s
    s = re.search(r'Duration:\s*(\d{2}):(\d{2}):(\d{2}\.\d+),', s)
    s = int(s.group(1)) * 3600 + int(s.group(2)) * 60 + float(s.group(3))
    return s


def cmd(src, dest, l):
    return 'ffmpeg -ss ' + str(pro) + '  -t ' + str(
        l - pro - epi) + ' -i ' + src + ' -vcodec copy -acodec copy ' + dest


for i in range(1, n + 1):
    # i = '%02d' % i
    i = str(i)
    src = r'd:\src' + '\\' + i + '.mp4'
    dest = r'd:\dest' + '\\' + i + '.mp4'
    os.system(cmd(src, dest, dur(src)))
